<template>
  <scroll-view scroll-y @scrolltolower="handleTolow" class="course_wrap">
    <block v-for="(item,index) in coursesList" :key="index">
      <courseList
        :item="item"
        :index="index"
        @ClickAppreciate="clickAppreciate"
        @ClickComment="clickComment"
        @ClickShare="clickShare"
        @ClickTitlePic="clickTitlepic"
      ></courseList>
    </block>
  </scroll-view>
</template>

<script>
//时间戳
import courseList from "../../../component/courseList.vue";
export default {
  components: {
    courseList
  },
  data() {
    return {
      coursesList: [],
      hasMore: true, //是否还有更多数据
      params: {
        //获取更多的参数
        limit: 10,
        skip: 0
      },
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    handleTolow() {
      console.log("到底啦");
      if (this.hasMore) {
        //还有更多的话修改参数
        this.params.skip += this.params.limit;
        this.getList();
      } else {
        uni.showToast({
          title: "已经没有数据了啦!",
          icon: "none"
        });
      }
    },
    getList() {
      this.request({
        url:
          this.apiServer +
          "/courses/findAllCourses?skip=" +
          this.params.skip +
          "&limit=" +
          this.params.limit
      }).then(res => {
        console.log(res);      
        if (res.data.length === 0) {
          this.hasMore = false;
          return;
        }
        this.coursesList = [...this.coursesList, ...res.data]; //拼接list
      });
    },
 
  }
};
</script>
<style lang="scss" scoped>
.course_wrap {
  height: calc(100vh - 100px);
}
</style>

